<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/layui/2.5.5/css/layui.css">
</head>
<body>
<form class="layui-form" action="" id="text">
    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input id="userId" type="text" name="userId" disabled="disabled" required  lay-verify="required" placeholder="请输入ID" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门</label>
        <div id="opt" class="layui-input-block">
            <select name="city" lay-verify="required">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo" id="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript" src="/webjars/jquery/3.1.1/jquery.js"></script>
<script type="text/javascript" src="/webjars/layui/2.5.5/layui.js"></script>
<script>
    /* layui.use('form', function(){
         var form = layui.form;
         /!*layer.msg(JSON.stringify(data.field));*!/
         form.on('submit(formDemo)', function(data){
             $.ajax({
                 type:"post",
                 url:"/Update",
                 data: JSON.stringify(data.field),
                 async:true,
                 contentType : "application/json;charsetset=UTF-8",//必须
                 dataType:"json",
                 success:function (data) {

                 }
             },JSON)
             return false;
         });
     });*/

    $(function () {
        layui.use('form', function(){
            var form = layui.form;
            /*layer.msg(JSON.stringify(data.field));*/
            form.on('submit(formDemo)', function(data){
                $.ajax({
                    type:"post",
                    url:"/UpdateDepartment",
                    data: JSON.stringify(data.field),
                    async:true,
                    contentType : "application/json;charsetset=UTF-8",//必须
                    dataType:"json",
                    success:function (data) {
                        if (data==true){
                            var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                            parent.layer.close(index);
                            layer.msg("修改成功")
                            window.parent.location.reload();
                        }
                    }, error: function () {
                        layer.msg("修改失败")
                    }
                },JSON)
                return false;
            });
        });

        /*全查询角色*/
        $.ajax({
            type:"post",
            url:"/SelectDepartment",
            data:{
            },
            async:true,
            dataType:"json",
            success:function (data) {
                $.each(data.data,function (index,item) {
                    var op="<option class='roleName'>"+item.departmentName+"</option>"
                    $('select[name="city"]').append(op)
                })
            }
        },JSON)
    })
</script>
</html>